#include <QCoreApplication>
#include "loger.h"
#include <QFile>
#include <QSharedPointer>

QSharedPointer<Loger> asd()
{
    QString accesLeavel;
    QString pythOrCons;
    QString name_txt="C:/Users/Anton/Downloads/logger/logger/logger/name_txt.txt";
    QFile file(name_txt);
    Loger::Leavel leavelAcces;
    if(!file.exists())
    {
    qDebug() << "File isn't exist";
    }
    file.open(QIODevice::ReadOnly);
    QTextStream in(&file);
             while (!in.atEnd())
             {
                 accesLeavel = in.readLine();
                 pythOrCons = in.readLine();
                 qDebug()<<accesLeavel;
             }
    file.close();
    if (accesLeavel=="INFO")
        leavelAcces= Loger::INFO;
    else if (accesLeavel == "WARNING")
        leavelAcces = Loger::WARNING;
    else if (accesLeavel== "ERROR")
        leavelAcces = Loger::ERROR;
    //Loger *log;
    QSharedPointer <Loger> log ;
    if (pythOrCons == "CONSOLE" || pythOrCons == "console" || pythOrCons == "Console")
    {
        log =QSharedPointer<Loger>(new ConsoleLoger(leavelAcces), &QObject::deleteLater);//new ConsoleLoger(leavelAcces);
    }
    else
    {
       log = QSharedPointer<Loger>(new FileLoger(leavelAcces,pythOrCons));//new FileLoger(leavelAcces,pythOrCons);
    }
    return log;
}

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    QSharedPointer<Loger>log = asd();
    log->log(Loger::INFO,"Hello");
    log->log(Loger::WARNING,"World");
    log->log(Loger::ERROR,"EST");
   // a.log(INFO,"Проверка");
    //delete log;
    return a.exec();

}

int loadLogger();

